package com.briup.smartcity.web.controller;

import com.briup.smartcity.aop.Logging;
import com.briup.smartcity.bean.Carousel;
import com.briup.smartcity.service.ICarouselService;
import com.briup.smartcity.utils.Result;
import com.briup.smartcity.utils.ResultUtil;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "轮播图模块")
@RestController
@RequestMapping("/auth/carousel")
public class CarouselController {
    @Autowired
    private ICarouselService service;

    @ApiOperation("根据id删除轮播图信息")
    @DeleteMapping("/deleteById")
    @Logging()
    public Result deleteCarouselById(Integer id){
        //2.调用service方法实现删除操作
        service.deleteById(id);

        return ResultUtil.success();
    }
    @ApiOperation("查询所有已启用的轮播图信息")
    @GetMapping("/find/yes")
    @Logging()
    public Result findCarouselWithYes(){
        //2.service层的代码
        List<Carousel> list = service.findYesCarousel();
        return ResultUtil.success(list);
    }


    @ApiOperation("分页查找轮播图信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "当前页",dataType = "int"),
            @ApiImplicitParam(name = "pageSize",value = "每页大小",dataType = "int")
    })
    @GetMapping("/page/query")
    @Logging()
    public Result findAllCarousel(Integer pageNum,Integer pageSize){
        //执行查询分页
        PageInfo<Carousel> pageInfo = service.findAll(pageNum, pageSize);
        return ResultUtil.success(pageInfo);
    }
    //添加 提供添加信息  存放数据库 id值  mysql 主键自增
    @ApiOperation("添加轮播图")
    @PostMapping("/save")
    @Logging()
    public Result addCarousel(Carousel carousel){
        //1.提交信息：名称 地址 描述
        System.out.println("轮播图对象："+carousel);
        //2.将保存的对象提交给service层保存方法
        service.saveCarousel(carousel);
        return ResultUtil.success();
    }
    @ApiOperation(value = "根据轮播图的状态",notes = "0 禁用 1 开启")
    @PutMapping("/update")
    @Logging()
    public Result updateCarousel(Carousel carousel){
        //1.接收到参数值 id 和 状态
        service.updateCarousel(carousel);
        return ResultUtil.success();
    }


}
